package com.zhongyu.controller;

import com.zhongyu.pojo.CangkuKucun;
import com.zhongyu.pojo.KucunPandian;
import com.zhongyu.pojo.User;
import com.zhongyu.service.KuCunPdService;
import com.zhongyu.vo.KuCunPdVo;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ResultVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 库存变动记录
 */
@RestController
@RequestMapping("/kucun/kcpd")
public class KuCunPdController {

    @Resource
    private KuCunPdService kuCunPdService;

    @GetMapping("/search/{pageNo}/{pageSize}")
    @RequiresPermissions("kcpdjl:list")
    public ResultVo search(@PathVariable Integer pageNo, @PathVariable Integer pageSize, KuCunPdVo kuCunPdVo) {
        PageResult pageResult = kuCunPdService.searchAll(pageNo, pageSize, kuCunPdVo);
        return ResultVo.success(pageResult);

    }

    @GetMapping("/list1")
    public ResultVo list1(Integer cangkuId, Integer goodsId) {
        List<KucunPandian> list = kuCunPdService.searchById(cangkuId, goodsId);
        return ResultVo.success(list);

    }

    @PostMapping("/pandian")
    public ResultVo pandian(@RequestBody CangkuKucun cangkuKuCun, String num,String beizhu, HttpSession session) {
        try {
            User loginUser = (User) session.getAttribute("loginUser");;
            return kuCunPdService.kuCunPanDian(cangkuKuCun,loginUser.getId(), Integer.valueOf(num),beizhu);
        } catch (Exception e) {
            return ResultVo.failure("库存盘点失败", e);
        }
    }
    @PostMapping("/pandian1")
    @RequiresPermissions("kcpd:list")
    public ResultVo pandian1(@RequestBody CangkuKucun cangkuKuCun, Integer num, HttpSession session) {
        try {
            User loginUser = (User) session.getAttribute("loginUser");;
            return kuCunPdService.kuCunPanDian(cangkuKuCun,loginUser.getId(), num,null);
        } catch (Exception e) {
            return ResultVo.failure("库存盘点失败", e);
        }
    }
}
